package com.wang;

import com.wang.builder.CallGraphBuilder;
import com.wang.printer.ResultPrinter;
import com.wang.tracer.CallChainTracer;

/**
 * 反向调用链追踪分析器主程序入口
 */
public class Main {
    // 配置参数（可根据实际项目修改）
    private static final String TARGET_METHOD_NAME = "RedisUtil.set";
    private static final String TARGET_CLASS_NAME = "RedisUtil";
    private static final String PROJECT_SOURCE_ROOT = "D:/ideaWorkSpacs/untitled/src/main/java";
    private static final String BASE_PACKAGE = "com.example";
    private static final int MAX_CHAIN_DEPTH = 10;

    public static void main(String[] args) {
        System.out.println("=== 反向调用链追踪代码影响分析器 ===");
        System.out.println("目标方法: " + TARGET_METHOD_NAME);
        System.out.println("项目路径: " + PROJECT_SOURCE_ROOT);
        System.out.println();

        // 1. 构建方法调用图
        System.out.println("第一阶段：构建方法调用图...");
        CallGraphBuilder graphBuilder = new CallGraphBuilder(PROJECT_SOURCE_ROOT, BASE_PACKAGE);
        graphBuilder.build();

        // 2. 追踪调用链
        System.out.println("第二阶段：反向追踪调用链...");
        CallChainTracer chainTracer = new CallChainTracer(
                graphBuilder.getAllMethods(),
                graphBuilder.getMethodCallGraph(),
                graphBuilder.getControllerApis(),
                TARGET_METHOD_NAME,
                TARGET_CLASS_NAME,
                MAX_CHAIN_DEPTH
        );
        chainTracer.trace();

        // 3. 输出结果
        System.out.println("第三阶段：生成影响分析报告...");
        ResultPrinter resultPrinter = new ResultPrinter(chainTracer.getImpactResults(), TARGET_METHOD_NAME);
        resultPrinter.print();
    }
}
